package com.example.administrator.ttphonehelper.process;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ProgressBar;
import android.widget.TextView;

import com.example.administrator.ttphonehelper.R;
import com.example.administrator.ttphonehelper.bean.ProcessBean;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2016/4/14 0014.
 */
public class ProcessFragment extends Fragment {
    private RecyclerView mRecyclerView;
    private RecyclerView.LayoutManager mLayoutManager;
    private ProcessAdapter mAdapter;
    private List<ProcessBean> mList;
    //控件
    private TextView mTvPhoneName;
    private TextView mTvPhoneType;
    private TextView mTvRamInfo;
    private Button mBtKillApp;
    private Button mBtShowSysApp;
    private ProgressBar mLoading;
    private ProgressBar mRom;
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_process,null);
        mRecyclerView= (RecyclerView) view.findViewById(R.id.process_recyclerView);
        mRecyclerView.setHasFixedSize(true);
        mList = new ArrayList<>();
        //得到数据
        getData();

        mLayoutManager = new LinearLayoutManager(getActivity());
        mRecyclerView.setLayoutManager(mLayoutManager);

        mAdapter = new ProcessAdapter(mList);
        mRecyclerView.setAdapter(mAdapter);
        return view;
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        //初始化控件
        initView();
    }

    private void initView() {
        //手机信息
        mTvPhoneName = (TextView) getView().findViewById(R.id.tv_process_name);
        mTvPhoneType = (TextView) getView().findViewById(R.id.tv_phone_type);
        mTvRamInfo = (TextView) getView().findViewById(R.id.tv_ram_info);
        mRom = (ProgressBar) getView().findViewById(R.id.pb_ram);
        //加载
        mLoading = (ProgressBar) getView().findViewById(R.id.pb_loading);
        //按钮
        mBtKillApp = (Button) getView().findViewById(R.id.bt_kill_process);
        mBtShowSysApp = (Button) getView().findViewById(R.id.bt_show_sys_app);
    }

    private List<ProcessBean> getData() {

       mList = ProcessManager.getInstance(getApplicationContext()).getProcess();
//        //测试数据
//        for (int i = 0; i < 10 ; i++) {
//            mList.add(new ProcessBean("测试进程"+i));
//        }
        return mList;
    }
    //获取全局上下文
    private Context getApplicationContext(){
        return getActivity().getApplicationContext();
    }
}
